import { getActiveProfile,stopProfile} from '@/api/kong/profile'
import {kongInfos} from '@/api/kong/kong'
const kong = {

    state: {
        // kong 全局配置文件
        kongSysProfile:{},
        kongInfo:{},
        
    },
    mutations: {
        SET_KONG_SYS_PROFILE:(state,kong_sys_profile) =>{
            state.kongSysProfile = kong_sys_profile;
        },
        SET_KONG_INFO:(state,kongInfo) =>{
            state.kongInfo = kongInfo;
        }
        
    },
    actions: {
        getKongActiveProfile({commit}){
            return new Promise((resolve, reject) =>{
                getActiveProfile().then(res =>{
                    const data=res.data;
                    if(data){
                        commit('SET_KONG_SYS_PROFILE', data);
                    }                    
                    resolve(data)
                }).catch(error => {
                    reject(error)
                });
            })            
        },
        stopKongActiveProfile({commit, state},profile){
            // console.log("stopKongActiveProfile传入参数："+JSON.stringify(profile))
            return new Promise((resolve,reject)=>{
                stopProfile(profile).then(res =>{
                    const code=res.code;
                    if(code===200){
                        commit('SET_KONG_SYS_PROFILE', '');
                    }
                    resolve(res)
                }).catch(err => {
                    reject(err)
                })
            })
        },
        // 
        getKongInfos({commit, state},kongInfo){
            return new Promise((resolve,reject) =>{
                kongInfos().then(res =>{
                    const code=res.code;
                    if(code===200){
                        commit('SET_KONG_INFO', res.data);
                    }
                    resolve(res);
                }).catch(err => {
                    reject(err)
                })
            })

        }
    }

}
export default  kong 